package com.ug_project.objects


infix fun <T> Array<T>.aggregateToString(split_string: String): String =
    this.toArrayList().aggregateToString(split_string)

infix fun <T> List<T>.aggregateToString(split_string: String): String {

    return aggregateToString(split_string){ it.toString() }

//    var temp = ""
//    for (index in this.indices) {
//        temp += this[index].toString()
//        if (index < size - 1)
//            temp += split_string
//    }
//    return temp
}


fun <T> List<T>.aggregateToString(split_string: String,action:(T)->Any): String {
    var temp = ""
    for (index in this.indices) {
        temp += action(this[index]).toString()
        if (index < size - 1)
            temp += split_string
    }
    return temp
}

fun <T> Array<T>.toArrayList(): ArrayList<T> {
    val arraylist = ArrayList<T>()
    arraylist.addAll(this)
    return arraylist
}

fun <T> List<T>.toArrayList(): ArrayList<T> {
    return ArrayList(this)
}

fun <T> List<T>?.isNullOrEmpty(action: () -> Unit): Boolean {
    if (isNullOrEmpty()) {
        action()
        return true
    }
    return false
}

fun <T> List<T>?.isNotNullOrNotEmpty(action: (List<T>) -> Unit): Boolean {
    if (this != null && this.isNotEmpty()) {
        action(this)
        return true
    }
    return false
}